package com.example.controller;

import com.example.pojo.Book;
import com.example.pojo.Staff;
import com.example.service.GuestService;
import com.example.service.StaffService;
import lombok.experimental.Accessors;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 名称StaffController
 * 描述StaffController
 *
 * @version 1.0
 * @author:wanghao
 * @datatime:2023,04,16,17,07
 */
@Controller
public class StaffController {
    @Autowired
    StaffService staffService;

    @Autowired
    GuestService guestService;


    @RequestMapping("/StaffLoginPage")
    public String StaffLoginPage(){return "StaffLoginPage";}

    @ResponseBody
    @RequestMapping("/StaffLogin")
    public String CheckStaffPasswd(@RequestParam(value = "name")String name,@RequestParam(value = "passwd")String passwd){
        if (staffService.CheckStaffPasswd(name, passwd).equals("true")) return "Succeed";
        else return "something wrong";
    }

    @RequestMapping("RegisterStaffPage")
    public String RegisterStaffPage(){return "RegisterStaffPage";}

    @ResponseBody
    @RequestMapping("RegisterStaff")
    public String RegisterStaff(Staff staff){
        int i = staffService.InsertStaff(staff);
        if (i>0)    return "Succeed";
        else return "something wrong";
    }

    @RequestMapping("InsertBookPage")
    public String InsertBookPage(){return "InsertBookPage";}

    @ResponseBody
    @RequestMapping("InsertBook")
    public String InsertBook(Book book){
        int i = staffService.InsertBook(book);
        if (i>0)
        {
            return "Insert Book Success";
        }
        else return "something wrong";
    }

    @RequestMapping("UpdateBookPage")
    public String UpdateBookPage(){return "UpdateBookPage";}

    @ResponseBody
    @RequestMapping("UpdateBook")
    public String UpdateBook(Book book)
    {
        int i = guestService.UpdateBook(book);
        if (i>0) return "Update Book Success";
        else return "something wrong";
    }
}
